// Sage Android Client.
// Connect to a Sage server, remotely execute commands and display results.
//
// Copyright (C) 2010, schilly <email@email.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

/**
 * 
 */

package org.sagemath.android.interacts;

import org.sagemath.android.Calculation;
import org.sagemath.android.R;

import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.SeekBar.OnSeekBarChangeListener;

/**
 * @author Harald Schilly
 */
public class SliderTest2 extends AbstractInteract {
  private TextView sliderTV;
  
  private int a = 0;
  
  /**
   */
  public SliderTest2() {
    super(R.layout.slider_test);
  }
  
  @Override
  protected void onResult(Calculation c) {
    sliderTV.setText("a: " + a + " and result: " + c.getResult());
  }
  
  @Override
  protected void onError(String msg) {
    sliderTV.setText("ERROR: " + msg);
  }
  
  @Override
  protected void init() {
    
    sliderTV = (TextView) myView.findViewById(R.id.SliderTestText);
    SeekBar sliderSB = (SeekBar) myView.findViewById(R.id.SliderTestSeekBar);
    
    sliderSB.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
      
      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        a = progress;
        calculate(Integer.toString(progress));
      }
      
      @Override
      public void onStartTrackingTouch(SeekBar seekBar) {
      }
      
      @Override
      public void onStopTrackingTouch(SeekBar seekBar) {
      }
    });
    
  }
  
  /*
   * (non-Javadoc)
   * @see org.sagemath.android.interacts.AbstractInteract#reset()
   */
  @Override
  public void reset() {
    onResult(new Calculation());
    a = 0;
  }
}
